/*
 * @Author: szx
 * @Date: 2021-11-14 12:37:55
 * @LastEditTime: 2021-11-14 12:40:46
 * @Description:
 * @FilePath: \leetcode\600-699\677\677.js
 */
var MapSum = function () {
    this.map = new Map();
};

/**
 * @param {string} key
 * @param {number} val
 * @return {void}
 */
MapSum.prototype.insert = function (key, val) {
    this.map.set(key, val);
};

/**
 * @param {string} prefix
 * @return {number}
 */
MapSum.prototype.sum = function (prefix) {
    let res = 0;
    for (const s of this.map.keys()) {
        if (s.startsWith(prefix)) {
            res += this.map.get(s);
        }
    }
    return res;
};

/**
 * Your MapSum object will be instantiated and called as such:
 * var obj = new MapSum()
 * obj.insert(key,val)
 * var param_2 = obj.sum(prefix)
 */
